package com.xq.demo;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.apache.catalina.User;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Test {




    private static int x=0,y=0;
    private static int a=0,b=0;
    private static Set<String> resultSet = new HashSet<String>();

    public static void main(String[] args) throws Exception{

        for(int i=0;i<=10000;i++){
            x=0;y=0;
            a=0;b=0;
            Thread one = new Thread(new Runnable() {
                @Override
                public void run() {
                    a=1;
                    x=b;
                }
            });
            Thread two = new Thread(new Runnable() {
                @Override
                public void run() {
                    b=1;
                    y=a;
                }
            });
            one.start();two.start();
            one.join();two.join();
            resultSet.add("(x="+x+",y="+y+")");
        }

        System.out.println(resultSet.toString());
        System.out.println("(x="+x+",y="+y+")");
       /* List<UserDto> list = getUserList();
        System.out.println(list);


        //1.过滤年龄大于25岁的
        List<UserDto> userList = list.stream().filter(user -> user.getAge() > 25).collect(Collectors.toList());
        System.out.println(JSON.toJSONString(userList));

        //2.过滤年龄小于29岁的，按dept分组，age倒序
        List<UserDto> userList2 = list.stream().filter(user -> user.getAge() < 30).collect(Collectors.toList());
        System.out.println(JSON.toJSONString(userList2));
        //dept分组，age排序
        Map<String, List<UserDto>> collect3 = userList2.stream().sorted(Comparator.comparing(UserDto::getAge).reversed())
                .collect(Collectors.groupingBy(UserDto::getDept));
        System.out.println(JSON.toJSONString(collect3));


        //3.抽象1.2种的公共方法
        List<UserDto> userList4 = getList(list,x->{return x>25;});
        System.out.println(JSON.toJSONString(userList4));
        List<UserDto> userList5 = getList(list,x->{return x<29;});
        System.out.println(JSON.toJSONString(userList5));*/



    }

    @FunctionalInterface
    public static interface MyLambdaInterface{
        boolean check(int age);
    }

    public static List<UserDto> getList(List<UserDto> list, MyLambdaInterface myLambdaInterface){
        List<UserDto> userList = list.stream().filter(user->myLambdaInterface.check(user.getAge())).collect(Collectors.toList());
        return userList;
    }


    public static List<UserDto> getUserList(){
        UserDto userInfoDto1 = new UserDto(1,"userName1","ERP",25);
        UserDto userInfoDto2 = new UserDto(2,"userName2","COM",29);
        UserDto userInfoDto3 = new UserDto(3,"userName3","COM",28);
        UserDto userInfoDto4 = new UserDto(4,"userName4","OA",25);
        UserDto userInfoDto5 = new UserDto(5,"userName5","SAC",28);
        return Arrays.asList(userInfoDto1,userInfoDto2,userInfoDto3,userInfoDto4,userInfoDto5);
    }




    static class UserDto{

        public UserDto(int id,String userName,String dept,int age){
            this.id=id;
            this.userName=userName;
            this.dept=dept;
            this.age=age;
        }
        private int id;
        private String userName;
        private String dept;
        private int age;

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getUserName() {
            return userName;
        }

        public void setUserName(String userName) {
            this.userName = userName;
        }

        public String getDept() {
            return dept;
        }

        public void setDept(String dept) {
            this.dept = dept;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }
}
